package com.ruoyi.constituent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.constituent.domain.GroupData;
import com.ruoyi.constituent.service.IGroupDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基团数据Controller
 * 
 * @author ruoyi
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/constituent/group")
public class GroupDataController extends BaseController
{
    @Autowired
    private IGroupDataService groupDataService;

    /**
     * 查询基团数据列表
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupData groupData)
    {
        startPage();
        List<GroupData> list = groupDataService.selectGroupDataList(groupData);
        return getDataTable(list);
    }

    /**
     * 导出基团数据列表
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:export')")
    @Log(title = "基团数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupData groupData)
    {
        List<GroupData> list = groupDataService.selectGroupDataList(groupData);
        ExcelUtil<GroupData> util = new ExcelUtil<GroupData>(GroupData.class);
        util.exportExcel(response, list, "基团数据数据");
    }

    /**
     * 获取基团数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(groupDataService.selectGroupDataByGroupId(groupId));
    }

    /**
     * 新增基团数据
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:add')")
    @Log(title = "基团数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupData groupData)
    {
        groupData.setCreatorId(getUserId());
        groupData.setCreator(getUsername());
        return toAjax(groupDataService.insertGroupData(groupData));
    }

    /**
     * 修改基团数据
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:edit')")
    @Log(title = "基团数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupData groupData)
    {
        return toAjax(groupDataService.updateGroupData(groupData));
    }

    /**
     * 删除基团数据
     */
    @PreAuthorize("@ss.hasPermi('constituent:group:remove')")
    @Log(title = "基团数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(groupDataService.deleteGroupDataByGroupIds(groupIds));
    }
}
